using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;

namespace Jonathan.Tabber
{
    public class TabberPage : UserControl
    {
        private TabButton m_Button;
        private bool m_Selected;
        private bool m_ShowClosed;
        private TabberGroup m_Group;
        private TabButton m_PreviousTab;

        public TabberPage () : this("")
        {
        }

        public TabberPage(String title)
        {
            this.m_Button = new TabButton(this);
            this.m_Button.ButtonText = title;
            this.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            this.m_Selected = false;
            this.m_PreviousTab = null;
            this.m_ShowClosed = true;
        }

        /// <summary>
        /// Changes Selected Tab to this one...
        /// </summary>
        public void SelectTab()
        {
            this.m_Group.ChangeTab(this.m_Button);
        }

        /// <summary>
        /// Sets the group of the TabberPage...
        /// </summary>
        /// <param name="group">TabberGroup</param>
        internal void SetGroup(TabberGroup group)
        {
            this.m_Group = group;
            this.m_Button.ContextMenuStrip = group.Tabber.TabContextMenuStrip;
        }

        /// <summary>
        /// This will close the TabberPage...
        /// </summary>
        public void ClosePage()
        {
            PageEventArgs pe = new PageEventArgs(this);
            this.m_Group.Tabber.SetRemoveEvent(pe);
            if (!pe.Cancel)
            {
                this.m_Group.RemoveTab(this);
                this.Dispose();
            }
        }

        /// <summary>
        /// Gets or Sets the value of the Previously Selected Tab...
        /// </summary>
        internal TabButton PreviousTab
        {
            get { return this.m_PreviousTab; }

            set { this.m_PreviousTab = value; }
        }

        /// <summary>
        /// Gets the group the TabberPage Belongs to...
        /// </summary>
        public TabberGroup Group
        {
            get { return this.m_Group; }
        }

        /// <summary>
        /// Gets or Sets the Tab Button...
        /// </summary>
        public TabButton TabButton
        {
            get { return this.m_Button; }

            set { this.m_Button = value; }
        }

        /// <summary>
        /// Gets or Sets if this TabberPage is Selected or not...
        /// </summary>
        public bool Selected
        {
            get { return this.m_Selected; }

            set
            {
                this.m_Selected = value;
                this.m_Button.Invalidate();
            }
        }

        /// <summary>
        /// Gets or Sets the Image displayed on the tab...
        /// </summary>
        public Image Image
        {
            get { return this.m_Button.Image; }

            set { this.m_Button.Image = value; }
        }

        /// <summary>
        /// Gets or Sets the Text Diaplayed on the Tab...
        /// </summary>
        public string TabTitle
        {
            get { return this.m_Button.ButtonText; }

            set { this.m_Button.ButtonText = value; }
        }

        /// <summary>
        /// Gets or Sets the Text Displayed on the tool tip...
        /// </summary>
        public string ToolTip
        {
            get { return this.m_Button.ButtonToolTip; }

            set { this.m_Button.ButtonToolTip = value; }
        }

        /// <summary>
        /// Gets or Sets if the Close Button will be shown...
        /// </summary>
        public bool ShowCloseButton
        {
            get { return this.m_ShowClosed; }

            set
            {
                this.m_ShowClosed = value;
                this.m_Button.CaclucateWidth();
            }
        }

        /// <summary>
        /// Gets the Page Info (this method needs to be overridden)...
        /// </summary>
        /// <returns>Empty String</returns>
        public virtual string GetPageInfo ()
        {
            return "";
        }
    }
}
